package com.adon.ar.test;

import android.location.Location;

public class ARpoi {
	
	protected Location poi_loc; // POI's location
	protected float poi_bearing; // bearing between POI and the direction user is facing
	
	protected float poi_bearing_by_north;	// bearing corresponding to north
	protected float poi_distance_to_user; // distance between user and POI
	
	// position on screen
	public int screenX;
	public int screenY = 160;
	public boolean shouldDisplay;
	
	public ARpoi(double longitude, double latitude, Location user_loc) {
		poi_loc = new Location(user_loc);
		poi_loc.setLatitude(latitude);
		poi_loc.setLongitude(longitude);
		poi_loc.setAltitude((Math.random()-0.5) * 4000);
		setPoi_bearing(user_loc);
		poi_distance_to_user = user_loc.distanceTo(poi_loc);
	}
	
	public Location getPoi_loc() {
		return poi_loc;
	}

	public float getPoi_bearing() {
		return poi_bearing;
	}
	
	public float getPoi_Altitude() {
		return (float) poi_loc.getAltitude();
	}
	
	public float getPoi_bearing_by_north() {
		return poi_bearing_by_north;
	}

	public float getPoi_distance_to_user() {
		return poi_distance_to_user;
	}

	public void setPoi_bearing(Location user_loc) {
		poi_bearing_by_north = user_loc.bearingTo(poi_loc);
		poi_bearing = (poi_bearing_by_north - user_loc.getBearing());
		poi_bearing = ARpoi.normalize_bearing(poi_bearing);
	}

	public void setPoi_distance_to_user(Location user_loc) {
		poi_distance_to_user = user_loc.distanceTo(poi_loc);
	}

	public ARpoi setBearingAndDistance(Location user_loc) {
		this.setPoi_bearing(user_loc);
		this.setPoi_distance_to_user(user_loc);
		return this;
	}

	public Location getLocation() {
		return this.poi_loc;
	}
	
	public static float normalize_bearing(float bearing) {
		if (bearing > 180) {
			bearing -= 360;
		} else if (bearing < -180) {
			bearing += 360;
		}
		return bearing;
	}

}
